package com.boctech.yxt.authcenter.config;

import com.boctech.yxt.authcenter.entity.JwtProperties;
import com.boctech.yxt.authcenter.filter.JwtAuthenticationTokenFilter;
import com.boctech.yxt.authcenter.service.MyUserDetailService;
import com.boctech.yxt.authcenter.utils.JwtTokenUtils;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

import javax.annotation.Resource;

@Configuration
@EnableConfigurationProperties(JwtProperties.class)
public class BeansConfig {

    @Resource
    private JwtProperties jwtProperties;

    @Resource
    private MyUserDetailService myUserDetailsService;


    @Bean
    public JwtTokenUtils jwtTokenUtil() {
        return new JwtTokenUtils(jwtProperties);
    }


    @Bean
    public JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter(
            JwtTokenUtils jwtTokenUtil) {
        return new JwtAuthenticationTokenFilter(
                this.jwtProperties,jwtTokenUtil,myUserDetailsService);
    }


}
